﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dominio;
using System.Data.OleDb;

namespace Persistencia
{
    public class FPersistencia : IPersistencia
    {
        private ConBD conexion;

        public void Agregar(OPersistente o)
        {
            Broker br = Broker.CrearBroker(o, conexion);
            try
            {
                br.Agregar(o);
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        public void Modificar(OPersistente o)
        {
            Broker br = Broker.CrearBroker(o, conexion);
            try
            {
                br.Modificar(o);
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        public void Eliminar(OPersistente o)
        {
            Broker br = Broker.CrearBroker(o, conexion);
            try
            {
                br.Eliminar(o);
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        public void TraerDatos(OPersistente o)
        {
            Broker br = Broker.CrearBroker(o, conexion);
            try
            {
                br.TraerDatos(o);
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        public List<OPersistente> TraerLista(OPersistente o)
        {
            Broker br = Broker.CrearBroker(o, conexion);
            try
            {
                return br.TraerLista(o);
            }
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }

        public void Conectarse(String cadena)
        {
            conexion = new ConBD();
            conexion.Conectarse(cadena);
        }

        public void Descontectarse()
        {
            conexion.Desconectarse();
        }
    }
}
